#define _WIN32_DCOM
#include <windows.h>
#include <iostream.h>
#include <stdio.h>

void main()
{
	CoInitialize(NULL);

	IRunningObjectTable* pRunningObjectTable;
	GetRunningObjectTable(NULL, &pRunningObjectTable);

	IEnumMoniker* pEnumMoniker;
	pRunningObjectTable->EnumRunning(&pEnumMoniker);

	IMoniker* pMoniker;
	IBindCtx* pBindCtx;
	OLECHAR* moniker_name;

	while(pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK)
	{
		CreateBindCtx(0, &pBindCtx);

		pMoniker->GetDisplayName(pBindCtx, NULL, &moniker_name);
		wprintf(L"DisplayName is %s\n", moniker_name);
		CoTaskMemFree(moniker_name);

    	DWORD mkSys;
		pMoniker->IsSystemMoniker(&mkSys);
		switch(mkSys)
		{
		case MKSYS_NONE:
			cout << "Custom moniker" << endl;
			break;
		case MKSYS_GENERICCOMPOSITE:
			cout << "Composite moniker" << endl;
			break;
		case MKSYS_FILEMONIKER:
			cout << "File moniker" << endl;
			break;
		case MKSYS_ANTIMONIKER:
			cout << "Anti moniker" << endl;
			break;
		case MKSYS_ITEMMONIKER:
			cout << "Item moniker" << endl;
			break;
		case MKSYS_POINTERMONIKER:
			cout << "Pointer moniker" << endl;
			break;
		case MKSYS_CLASSMONIKER:
			cout << "Class moniker" << endl;
			break;
		default:
			cout << "Unknown system moniker" << endl;
		}

		pMoniker->Release();
		pBindCtx->Release();
	}
	
	pRunningObjectTable->Release();
	pEnumMoniker->Release();
	CoUninitialize();
}